package com.wl.method;

import java.util.Scanner;

/**
 * 计算器，要求实现加减乘除功能，并且能够循环接收新的数据，通过用户交互实现
 */
public class Calculator {
    /**
     * 写4个方法:加减乘除
     * 利用循环+ switch进行用户交互
     * 传递需要操作的两个数
     * 输出结果
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextDouble()){
            double num1 = scanner.nextDouble();;
            String mark = scanner.next();
            double num2 = scanner.nextDouble();
            switch(mark){
                case "+":
                    add(num1,num2);
                    break;
                case "-":
                    minus(num1,num2);
                    break;
                case "*":
                    multiply(num1,num2);
                    break;
                case "/":
                    except(num1,num2);
                    break;
                default:
                    System.out.println("请正确输入");
                    break;
            }
            System.out.println("输出任意字母退出");
        }
        scanner.close();
    }
    private static void add(double num1,double num2){
        System.out.println(num1+num2);
    }
    private static void minus(double num1,double num2){
        System.out.println(num1-num2);
    }
    private static void multiply(double num1,double num2){
        System.out.println(num1*num2);
    }
    private static void except(double num1,double num2){
        if (num2 == 0){
            System.out.println("分母不可为0");
        }else{
            System.out.println(num1/num2);
        }
    }
}
